﻿Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.IO
Imports System.Runtime.Serialization


' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class ProcessCallback
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
       Return "Hello World"
    End Function

    <WebMethod()> _
    Public Sub PostConfirmation(ByVal correlationId As String, ByVal TransactionResult As ResponseInfo)

        ' Obtain the runtime value of the Text input argument
        'ConstituentDataContract theData = context.GetValue(this.ConstituentData);
        'Dim theData As Object = Context.GetValue(TransactionResult)

        Dim logFileName As String = "CallbackMessages.txt"
        Dim logPath As String = "C:\PublicLogs\" 'AppDomain.CurrentDomain.BaseDirectory 'Environment.CurrentDirectory;

        Dim ms As New MemoryStream()

        Dim serializer As New DataContractSerializer(GetType(ResponseInfo))
        serializer.WriteObject(ms, TransactionResult)


        Dim outStream As New FileStream(logPath + "\" + logFileName, FileMode.Append, FileAccess.Write, FileShare.Read)

        'FileStream outStream = File.OpenWrite("C:\\ConstituentDataContract.txt")
        'ms.WriteTo("REQUEST:" & DateTime.Now.ToLongDateString());

        AddText(outStream, String.Concat(DateTime.Now.ToShortDateString(), " ", DateTime.Now.ToShortTimeString(), Environment.NewLine))
        ms.WriteTo(outStream)

        For Each curErrorDetailInfo As ErrorDetailInfo In TransactionResult.Details
            AddText(outStream, curErrorDetailInfo.faultDescription)
        Next

        AddText(outStream, Environment.NewLine)
        AddText(outStream, Environment.NewLine)

        outStream.Flush()


        outStream.Close()






        'System.Runtime.Serialization.DataContractSerializer ser = new System.Runtime.Serialization.DataContractSerializer(








    End Sub



    Private Sub AddText(ByVal fs As FileStream, ByVal value As String)

        Dim info As Byte() = New UTF8Encoding(True).GetBytes(value)
        fs.Write(info, 0, info.Length)
    End Sub





End Class